<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<button class="stop">stop</button>
<button class="begin">begin</button>
<script>
  var begin = document.querySelector('.begin');
  var stop = document.querySelector('.stop');
  let timer = null;

  begin.addEventListener('click', function () {
    timer = setInterval(function () {
      console.log('setInterval');
    }, 1000)
  })

  stop.addEventListener('click', function () {
    clearInterval(timer)
  })
</script>
</body>
</html>